package cn.online.service;

import java.util.List;

import cn.online.dao.TeacherDao;
import cn.online.model.Teacher;

public class TeacherService {
	
	private TeacherDao teacherDao;

	public void setTeacherDao(TeacherDao teacherDao) {
		this.teacherDao = teacherDao;
	}
	
	public void insert(Teacher teacher){
			teacherDao.save(teacher);
	}
	
	public void deleteTeachers(Integer ids[]){
		Teacher teacher = null;
		for(int id:ids){
			teacher=teacherDao.findById(id);
			if(teacher!=null){
				teacherDao.delete(teacher);
			}
		}
	}
	
	public void updateTeacher(Teacher teacher){
		if(teacher!=null)
			teacherDao.update(teacher);
	}
	
	public List<Teacher> getTeacherList(){
		return teacherDao.findAll();
	}
	
	public Teacher findById(Integer id){
		return teacherDao.findById(id);
	}
	
	public Teacher login(String username,String password) {
		return teacherDao.get(username, password);
	}
	
	public Teacher findByName(String username){
		return teacherDao.get(username);
	}
}
